﻿using Irony.Parsing;
using NMF.Languages.AnyText.ClassConstruction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NMF.Languages.AnyText
{
    public class BooleanTypeTerminal : DataTypeTerminal<BooleanType>
    {
        protected BooleanTypeTerminal(string name, BooleanType type)
            : base(name, type)
        {

        }

        public BooleanTypeTerminal(string name) : this(name, new BooleanType()) { }

        public override DataTypeTerminal<BooleanType> CreateCustom()
        {
            return new BooleanTypeTerminal("CustomBoolean", new BooleanType());
        }

        public override BnfExpression CreateRule(AnyTextGrammar grammar)
        {
            var trueTerm = grammar.ToTerm(DataType.TrueString);
            var falseTerm = grammar.ToTerm(DataType.FalseString);

            grammar.MarkReservedWords(trueTerm, falseTerm);

            return trueTerm | falseTerm;
        }

        public override object GetValue(ParseTreeNode node)
        {
            var val = node.ChildNodes[0].Token.ValueString;
            var comparison = Grammar.CaseSensitive ? StringComparison.CurrentCulture : StringComparison.CurrentCultureIgnoreCase;
            if (string.Equals(val, DataType.TrueString, comparison))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
